class MyPageHeader extends BaseEditMaster {
    constructor(dataId, currentTaskPrivileges, nextTaskPrivileges, pageStatus, pageListData,
            returnUrl, fetchDataUrl, saveUrl, exportUrl, printUrl) {
        super(dataId, currentTaskPrivileges, nextTaskPrivileges, pageStatus, pageListData,
                returnUrl, fetchDataUrl, saveUrl, exportUrl, printUrl);
        this.checkUrl = "/trade/master_production_schedule/check.html";
        this.uncheckUrl = "/trade/master_production_schedule/uncheck.html";
    }
    // 得到产品计划数据
    GetEntityData() {
        let item = {};
        item['headerId'] = $("#HeaderId").val();
        item['contractNo'] = $.trim($("#ContractNo").val());                          // 合同号
        item['dateOfContract'] = $.trim($("#DateOfContract").val());                  // 日期        
        item['tradeModeId'] = formatNullInputValue($.trim($("#TradeModeId").val()));  // 贸易方式
        item['serialNo'] = $.trim($("#SerialNo").val());                              // 系列号
        item['saledBy'] = $.trim($("#SaledBy").val());                            // 国际贸易担当
        item['description'] = formatNullInputValue($.trim($("#Description").val()));  // 备注
        item['createdBy'] = $.trim($("#UserId").val());
        item['updatedBy'] = $.trim($("#UserId").val());

        return JSON.stringify(item);
    }
    FillData(data) {
        let item = data.HeaderEntity;
        $("#HeaderId").val(item.headerId);
        $("#ContractNo").val(item.contractNo);
        $("#DateOfContract").val(formatNullData(item.dateOfContract));
        $("#TradeModeId").val(item.tradeModeId);
        $("#TradeModeName").val(item.tradeModeName);
        $("#SerialNo").val(item.serialNo);
        $("#SaledBy").val(item.saledBy);
        $("#SaledByName").val(item.saledByName);
        $("#UpdatedBy").val(item.updatedBy);
        $("#UpdatedByName").val(item.updatedByName);
        $("#UpdatedDate").val(item.updatedDate);
        $("#Description").val(item.description);
        $("#QuoteFlag").val(item.quoteFlag);
        // 完成标记
        if (parseInt(item.overFlag) === 1) {
            $("#OverFlag").prop("checked", true);
        } else {
            $("#OverFlag").prop("checked", false);
        }
        // 最后的审核人、审核日期
        $("#CheckedBy").val(item.checkedBy);
        $("#CheckedByName").val(item.checkedByName);
        $("#CheckedDate").val(item.checkedDate === null ? '' : item.checkedDate);
        $("#CheckedStatus").val(item.checkedStatus);
        $('#FlowOrderNo').val(item.flowOrderNo);

        // 得到计划跟踪项目
        _InstancePageLines.mpsItemNode = data.MpsItemNode;
        // 重建明细表头
        _InstancePageLines.BuildDataTableHeader();
        // 显示明细数据
        _InstancePageLines.BuildDataTable(data.LinesList);

        this.currentTaskPrivileges = item.currentTaskPrivileges;
        this.nextTaskPrivileges = item.nextTaskPrivileges;
        this.unCheckFlag = item.unCheckFlag;
        this.SetPageElementStatus(this.HidePageElement, this.ShowPageElement, function () {
            _InstancePageLines.AutoAdjustTableHeightForLines();
        });
    }
    Save() {
        super.Save(function (data, $self) {
            if (data > 0) {
                if (parseInt($self.pageSstatus) === 1) {
                    $("#HeaderId").val(data);   // 设置刚才插入的记录ID
                    $self.dataId = data;
                    $("#panelSlave").show();
                    $("#ButPrint").show();
                    $("#IsChecked").removeClass().addClass("n2");
                    $("#IsChecked").html("状态：未审核。");
                    $("#IsChecked").show();
                }
            }
        });
    }
    New() {
        super.New();
        // 默认设置一些值
        $("#SaledBy").val($("#UserId").val());
        $("#SaledByName").val($("#UserName").val());
        $("#DateOfContract").val(getCurrentDate());
        $('#tabData11 tbody').empty();
        $('#tabData12 tbody').empty();
        $("#panelSlave").hide();
        this.rows = 0;
        $(".switcher").hide();
        //自适应高度
        _InstancePageLines.AutoAdjustTableHeightForLines();
        $("#ContractNo").focus();
    }
    DoChoiceSaledBy() {
        let _choice = new CommonChoice();
        _choice.DoChoiceUser(0, '选择国际贸易担当', '贸易', (data) => {
            if (data) {
                // 判断是否数据发生了改变如果改变则设置改变标记
                if ($("#SaledByName").val() !== data[1]) {
                    $("#form_data").data("changed", true);
                }
                $("#SaledBy").val(data[0]);
                $("#SaledByName").val(data[1]);
                $("#SaledByName").focus();
            }
        });
    }
    DoChoiceTradeMode() {
        let _choice = new CommonChoice();
        _choice.DoChoiceTradeMode(0, (data) => {
            if (data) {
                // 判断是否数据发生了改变如果改变则设置改变标记
                if ($("#TradeModeName").val() !== data[1]) {
                    $("#form_data").data("changed", true);
                }
                $("#TradeModeId").val(data[0]);
                $("#TradeModeName").val(data[1]);
                $("#TradeModeName").focus();
            }
        });
    }
    DoPrintPreview() {
        window.open(parent.basePath + "/trade/master_production_schedule/print.html?id=" + $("#HeaderId").val());
    }
    Expand() {
        super.Expand(function () {
            // 自适应高度
            _InstancePageLines.AutoAdjustTableHeightForLines();
        });
    }
    /* 折叠 */
    Collapse() {
        super.Collapse(function () {
            // 自适应高度
            _InstancePageLines.AutoAdjustTableHeightForLines();
        });
    }
    DoCheck() {
        super.DoCheck(function (data, $self) {
            // 显示明细数据
            _InstancePageLines.BuildDataTable(data.LinesList);
            // 设置画面各个元素状态
            $self.SetPageElementStatus($self.HidePageElement, $self.ShowPageElement, function () {
                _InstancePageLines.AutoAdjustTableHeightForLines();
            });
        });
    }
    Uncheck() {
        super.Uncheck(function (data, $self) {
            // 显示明细数据
            _InstancePageLines.BuildDataTable(data.LinesList);
            // 设置画面各个元素状态
            $self.SetPageElementStatus($self.HidePageElement, $self.ShowPageElement, function () {
                _InstancePageLines.AutoAdjustTableHeightForLines();
            });
        });
    }
    ShowPageElement() {
        $("Button.act__save").show();
        if (!$("span.act__delete").hasClass("act__delete")) {
            $("span.act__delete").addClass("trash");
            $("span.act__delete i").addClass("fa-all fa-trash-o fa-1");
        }
    }
    HidePageElement() {
        //$("Button.act__save").hide();
        //$("span.act__delete").removeClass("trash");
        //$("span.act__delete i").removeClass("fa-all fa-trash-o fa-1");
    }
    SetOverFlag() {
        let _params = {};
        _params['HeaderId'] = parseInt($("#HeaderId").val());
        _params['OverFlag'] = $("#OverFlag").is(":checked") ? "1" : "0";  // 完成标记
        this.DoAjax(_params, "/trade/master_production_schedule/setOverFlag.html", function () {
            ShowSuccessMessagePanel("完成状态设置成功。");
        });
    }
}

class MyPageLines extends BaseEditSlave {
    constructor() {
        super('', '', '');
        this.mpsItemNode = [];
        this.selectedItemList = [];
    }
    BuildDataTableHeader() {
        // 形成颜色表头 
        let _th = '';
        let _colWidth = 0;
        let _col = '';
        if ((this.mpsItemNode !== null) && (this.mpsItemNode.length > 0)) {
            for (let i = 0; i < this.mpsItemNode.length; i++) {
                _col += '<col style="width:150px;" />';
                _colWidth += 150;
                _th += '<th class="edit__column">' + this.mpsItemNode[i].itemName + '</th>';
            }
        }
        let w = $(window).width() - 728 - 16 - 17;
        let _w_desc = (w - _colWidth) < 400 ? 400 : (w - _colWidth);
        _col += '<col style="' + _w_desc + 'px;" />';
        _th += '<th class="edit__column">备注</th>';
        _colWidth += _w_desc;
        $("#tabHeader12").css({width: _colWidth});
        $("#tabData12").css({width: _colWidth - 17});
        $("#tabHeader12 thead tr").empty();
        $("#tabHeader12 colgroup").empty();
        $("#tabData12 colgroup").empty();
        $("#tabHeader12 colgroup").html(_col);
        $("#tabData12 colgroup").html(_col);
        $("#tabHeader12 thead tr").html(_th);
    }
    BuildDataTable(result) {
        $('#tabData11 tbody').empty();
        $('#tabData12 tbody').empty();
        // 得到数据列表
        if (result === null || result.length === 0) {
            this.rows = 0;
            // 自适应高度
            _InstancePageLines.AutoAdjustTableHeightForLines();
            return false;
        }
        let content01 = '';
        let content02 = '';
        this.rows = result.length;
        this.numCheckbox = result.length;
        for (let i = 0; i < result.length; i++) {
            let id = result[i].linesId;
            content01 += '<tr _mash_id="' + id + '" _productId="' + result[i].productId + '">';
            content01 += '<td rowspan="3" style="vertical-align:middle;"><label style="margin-left:3px;" class="btn" for="R-' + id + '"><input id="R-' + id + '" name="_check_row" type="checkbox" onclick="_InstancePageLines.DoCheckRow($(this),\'_check_row\', $(\'#CheckAll\'));" value="' + id + '"/><i></i><span></span></label></td>';
            // 删除权限判断
            if ($("#ActionAcl_4").length === 0 || parseInt($("#ActionAcl_4").val() === 0)) {
                content01 += '<td rowspan="3"></td>';
            } else {
                content01 += '<td rowspan="3" class="column__action"><span title="删除" class="trash act__delete" onclick="_InstancePageLines.DeleteLines($(this));"><i class="fa-all fa-trash-o fa-1"></i></span></td>';
            }
            content01 += '<td rowspan="3" style="vertical-align:middle;">' + formatNullData(result[i].customerName) + '</td>';
            content01 += '<td rowspan="3" style="vertical-align:middle;">' + formatNullData(result[i].styleNo) + '</td>';
            content01 += '<td rowspan="3" style="vertical-align:middle;" class="edited-cell">' + formatNullData(result[i].quantity) + '</td>';
            content01 += '<td rowspan="3" style="vertical-align:middle;" class="edited-cell">' + formatNullData(result[i].productColour) + '</td>';
            content01 += '<td class="cell__01" style="text-align:center;">预定日</td>';
            content01 += '</tr>';
            content01 += '<tr>';
            content01 += '<td class="cell__02" style="text-align:center;">履行日</td>';
            content01 += '</tr>';
            content01 += '<tr>';
            content01 += '<td class="cell__03" style="text-align:center;">状&nbsp;&nbsp;&nbsp;况</td>';
            content01 += '</tr>';

            // 计划
            content02 += '<tr class="01" style="height:25px;">';
            if (this.mpsItemNode !== null) {
                for (let j = 0; j < this.mpsItemNode.length; j++) {
                    let _itemId = this.mpsItemNode[j].itemId.toString();
                    let _t = false;
                    $.each(result[i].planSchema, function (index, data) {
                        if (data.ItemId === _itemId) {
                            content02 += '<td class="edited-cell">' + formatNullData(data.Plan) + '</td>';
                            _t = true;
                            return false;
                        }
                    });
                    if (_t === false)
                        content02 += '<td class="edited-cell"></td>';
                }
            }
            content02 += '<td rowspan="3" style="border-right:none; vertical-align:middle;" class="edited-cell">' + formatNullData(result[i].description) + '</td>';    //备注
            content02 += '</tr>';
            // 履行日
            content02 += '<tr class="01" style="height:25px;">';
            if (this.mpsItemNode !== null) {
                for (let j = 0; j < this.mpsItemNode.length; j++) {
                    let _itemId = this.mpsItemNode[j].itemId.toString();
                    let _t = false;
                    $.each(result[i].actualSchema, function (index, data) {
                        if (data.ItemId === _itemId) {
                            content02 += '<td class="edited-cell">' + formatNullData(data.Actual) + '</td>';
                            _t = true;
                            return false;
                        }
                    });
                    if (_t === false)
                        content02 += '<td class="edited-cell"></td>';
                }
            }
            content02 += '</tr>';
            // 状况
            content02 += '<tr class="02" style="height:25px;">';
            if (this.mpsItemNode !== null) {
                for (let j = 0; j < this.mpsItemNode.length; j++) {
                    let _itemId = this.mpsItemNode[j].itemId.toString();
                    let _t = false;
                    $.each(result[i].statusSchema, function (index, data) {
                        if (data.ItemId === _itemId) {
                            content02 += '<td class="edited-cell" title="' + formatNullData(data.Status) + '">' + formatNullData(data.Status) + '</td>';
                            _t = true;
                            return false;
                        }
                    });
                    if (_t === false)
                        content02 += '<td class="edited-cell"></td>';
                }
            }
            content02 += '</tr>';
            $('#tabData11 tbody').append(content01);
            $('#tabData12 tbody').append(content02);
            content01 = '';
            content02 = '';
        }
        // 设置明细部分高度
        this.AutoAdjustTableHeightForLines();

        let id = "cellField";
        let name = "_cellField";
        $('#tabData11 tbody tr').find("td.edited-cell").click(function () {
            switch ($(this).index()) {
                default:
                    OnCellClickEvent($(this), id, name, 0);
                    break;
            }
        });
        // 计划、履行日行编辑设定
        $('#tabData12 tbody tr.01').find("td.edited-cell").click(function () {
            switch ($(this).index()) {
                // 备注字段
                case $('#tabData12 tbody tr').find("td.edited-cell").last().index() + 1:
                    OnCellClickEvent($(this), id, name, 0);
                    break;
                default:
                    OnCellDateEditEvent($(this), id, name);
                    break;
            }
        });
        // 状况行编辑设定
        $('#tabData12 tbody tr.02').find("td.edited-cell").click(function () {
            OnCellClickEvent($(this), id, name, 0);
        });

        setTwoTableRowColor("tabData11", "tabData12");
    }
    GetLinesData() {
        let _this = this;
        let _result = [];
        // 得到修改过数据
        $('#tabData11 tbody').find("tr").each(function (index) {
            let _scheduleId = $.trim($(this).attr("_mash_id"));       // 计划ID
            if (_scheduleId !== "") {   // 排除空行
                let $tr2_plan = $('#tabData12 tbody').find("tr").eq(index);
                let $tr2_actual = $('#tabData12 tbody').find("tr").eq(index + 1);
                let $tr2_status = $('#tabData12 tbody').find("tr").eq(index + 2);
                // 判断当前行是否有更新数据
                if ($(this).find("td.dirty").length > 0 || $tr2_plan.find("td.dirty").length > 0 ||
                        $tr2_actual.find("td.dirty").length > 0 || $tr2_status.find("td.dirty").length > 0) {
                    let item = {};
                    item['linesId'] = _scheduleId;
                    item['quantity'] = formatNullInputValue($.trim($(this).find('td').eq(4).text())) === null ? 0 : $.trim($(this).find('td').eq(4).text());                    // 数量
                    item['styleNo'] = $.trim($(this).find('td').eq(3).text());                             // 款号
                    item['productColour'] = formatNullInputValue($.trim($(this).find('td').eq(5).text())); // 产品颜色
                    item['desctiption'] = formatNullInputValue($.trim($tr2_plan.find('td').eq($tr2_plan.find("td").last().index()).text())); // 备注
                    item['updatedBy'] = $("#UserId").val();
                    // 取得跟踪数据
                    let _trackSchemaList = [];
                    for (let j = 0; j < _this.mpsItemNode.length; j++) {
                        let _item = {};
                        _item['headerId'] = $("#HeaderId").val();
                        _item['parentLinesId'] = _scheduleId;
                        _item['itemId'] = _this.mpsItemNode[j].itemId;
                        _item['plan'] = formatNullInputValue($.trim($tr2_plan.find("td").eq(j).text()));
                        _item['actual'] = formatNullInputValue($.trim($tr2_actual.find("td").eq(j).text()));
                        _item['status'] = formatNullInputValue($.trim($tr2_status.find("td").eq(j).text()));
                        _trackSchemaList.push(_item);
                    }
                    item['trackSchemaList'] = _trackSchemaList;

                    _result.push(item);
                }
            }
        });
        //return JSON.stringify(jsonResult);
        return _result;
    }
    // 批量选择的数据(类中data:this.GetCheckedLinesData)
    GetCheckedLinesData() {
        let choiced_data = [];
        if ($("input[type='checkbox'][name='_check_row']:checked").length > 0) {
            $("input[type='checkbox'][name='_check_row']:checked").each(function () {
                let item = {};
                item['headerId'] = $("#HeaderId").val();
                item['linesId'] = $(this).parent().parent().parent().attr("_mash_id");
                item['deletedBy'] = $.trim($("#UserId").val());
                choiced_data.push(item);
            });
        }
        return JSON.stringify(choiced_data);
    }
    SaveLines() {
        //step 1、进行页面验证，失败则返回
        //let success_01 = CheckGridInput();
        //if (!success_01)
        //    return;

        super.DoAjax(this.GetLinesData(), "/trade/master_production_schedule/lines/update.html", (data, _this) => {
            $('#tabData11 tbody').find("td.dirty").removeClass("dirty");
            $('#tabData12 tbody').find("td.dirty").removeClass("dirty");
            ShowSuccessMessagePanel("保存成功。");
        });
    }
    DeleteLines($self) {
        let params = {};
        params['HeaderId'] = parseInt($("#HeaderId").val());
        params['LinesId'] = $self.parent().parent().attr("_mash_id");
        params['DeletedBy'] = $.trim($("#UserId").val());
        params['LinesData'] = "款号：" + $self.parent().parent().find("td").eq(3).text() +
                "　颜色：" + $self.parent().parent().find("td").eq(5).text();
        super.DeleteLines(params, "/trade/master_production_schedule/lines/delete.html", function (data, _this) {
            if (data.LinesList !== undefined) {
                // 刷新明细
                _this.BuildDataTable(data.LinesList);
            }
            ShowSuccessMessagePanel('删除成功。');
        });
    }
    NewLines() {
        let _choice = new CommonChoice();
        _choice.DoChoiceProduct(1, '选择产品', (data) => {
            if (data) {
                let _result = [];
                for (let i = 0; i < data.length; i++) {
                    let item = {};
                    item['headerId'] = parseInt($("#HeaderId").val());
                    item['productId'] = parseInt(data[i].productId);
                    item['styleNo'] = data[i].styleNo;
                    item['productColour'] = "";
                    item['createdBy'] = parseInt($.trim($("#UserId").val()));
                    item['updatedBy'] = parseInt($.trim($("#UserId").val()));
                    item['workFlowId'] = parseInt($("#WorkFlowId").val());

                    _result.push(item);
                }
                // 保存，根据所选产品款号，增加明细表记录
                super.DoAjax(_result, "/trade/master_production_schedule/lines/insert.html", (data, _this) => {
                    $("#SerialNo").val(data.HeaderEntity.serialNo);
                    _this.BuildDataTable(data.LinesList);
                    ShowSuccessMessagePanel("增加成功。");
                });
            }
        });
    }
    // 同步更新计划跟踪项目
    SyncUpdateTrackItem() {
        if ($("input[type='checkbox'][name='_check_row']:checked").length <= 0) {
            ShowErrorMessagePanel("请选择要更跟踪的数据。");
            return false;
        }

        showModal(795, 468, '同步更新计划跟踪项目', parent.basePath + '/trade/master_production_schedule/lines/track_item/edit.html', null, ($dialog) => {
            let _exist = $.inArray($dialog, parent.arrDialog);
            if (_exist >= 0) {
                parent.arrDialog.splice($.inArray($dialog, parent.arrDialog), 1);
                /*
                 // 清空选择的数据
                 $.each($("input[type='checkbox'][name='_check_row']:checked"), (index, data) => {
                 this.click();
                 });
                 this.selectedItemList = [];
                 $("#CheckAll").prop("checked", false);
                 */
            }
            // 清空选择的数据
            parent.arrChoice.splice(0, parent.arrChoice.length);
            parent.choice_success = false;
        });
    }
    // 设置行选择后的状态
    SetRowStatus($self) {
        let _this = this;
        let key = $self.val();
        super.AdjustRowStatus($self, function ($row, index) {
            $('#tabData12 tbody tr:eq(' + index + ')').addClass("row__selected");
            $('#tabData12 tbody tr:eq(' + (index + 1) + ')').addClass("row__selected");
            $('#tabData12 tbody tr:eq(' + (index + 2) + ')').addClass("row__selected");
            // 设置删除按钮失效
            $row.children('td').eq(1).children('span').eq(0).attr("onclick", "");
            let item = {};
            item['linesId'] = key;
            _this.selectedItemList[key] = item;
        }, function ($row, index) {
            $('#tabData12 tbody tr:eq(' + index + ')').removeClass("row__selected");
            $('#tabData12 tbody tr:eq(' + (index + 1) + ')').removeClass("row__selected");
            $('#tabData12 tbody tr:eq(' + (index + 2) + ')').removeClass("row__selected");
            // 设置删除按钮有效
            let _event_delete_onclick = '_InstancePageLines.DeleteLines($(this))';
            $row.children('td').eq(1).children('span').eq(0).attr("onclick", _event_delete_onclick);
            delete _this.selectedItemList[key];
        });
    }
    // 恢复选择状态
    ResetSelectRowStatus() {
        let _this = this;
        $("#tabData11 tbody").find("tr").each(function (index) {
            let key = $(this).attr("_mash_id");
            if (_this.selectedItemList[key] !== undefined) {
                $(this).children("td").eq(0).children("label").eq(0).children("input[type='checkbox'][name='_check_row']").eq(0).prop('checked', true);
                $(this).addClass("row__selected");

                $('#tabData12 tbody tr:eq(' + index + ')').addClass("row__selected");
                $('#tabData12 tbody tr:eq(' + (index + 1) + ')').addClass("row__selected");
                $('#tabData12 tbody tr:eq(' + (index + 2) + ')').addClass("row__selected");
                // 设置删除按钮失效
                $(this).children('td').eq(1).children('span').eq(0).attr("onclick", "");
            }
        });
        // 设置选择全部的状态
        let n = $("input[type='checkbox'][name='_check_row']:checked").length;
        if (n < $("#tabData11 tbody").find("tr").length || n === 0) {
            $("#CheckAll").prop("checked", false);
        } else {
            $("#CheckAll").prop("checked", true);
        }
    }
    AutoAdjustTableHeightForLines() {
        let h = $(window).height();
        let _tabTop = $("#divH11").offset().top + 26;   // 用于随着窗口变化，下面明细高度随之变化的一个节点
        let _rc = Math.floor((h - _tabTop - 25) / 75);
        let _dh = _rc * 75 + 17;
        let _rowH = this.rows * 75 + 17; // 计算行高
        _dh = (_rowH >= _dh) ? _dh : _rowH;

        $("#divD11").css({"max-height": _dh - 17, height: _dh - 17});
        $("#divD12").css({"max-height": _dh + 1, height: _dh + 1});
        let w = $("#panelSlaveData_01").width();
        $("#divD12").css({left: -1, width: w - 728 + 1});
    }
    ScrollTo() {
        $('#divH12').scrollLeft($('#divD12').scrollLeft());
        $('#divD11').scrollTop($('#divD12').scrollTop());
    }
}

var _InstancePageHeader = null;
var _InstancePageLines = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    let _pageStatus = parseInt($("#Action").val());
    let _dataId = $("#HeaderId").val();

    let master_production_schedule_list_result = $.cookie("master_production_schedule_list_result") === undefined ? "" : $.cookie("master_production_schedule_list_result");
    let _pageListData = [];
    if (master_production_schedule_list_result !== "") {
        _pageListData = master_production_schedule_list_result.split(',');
        $("#rec_total_rows").text(_pageListData.length);
        $("#rec_cur_row").text($.inArray(_dataId, _pageListData) + 1);

        if (_pageListData.length > 0) {
            let index = $.inArray(_dataId, _pageListData);
            if (index === 0) {
                $("#ButPrev").attr("disabled", "disabled");
            } else {
                $("#ButNext").removeAttr("disabled");
            }
            if (index === (_pageListData.length - 1)) {
                $("#ButNext").attr("disabled", "disabled");
            } else {
                $("#ButPrev").removeAttr("disabled");
            }
        }
    } else {
        $("#rec_total_rows").text("1");
        $("#rec_cur_row").text("1");
    }

    _InstancePageHeader = new MyPageHeader(_dataId, 0, 0, _pageStatus, _pageListData,
            "/trade/master_production_schedule/list.html",
            "/trade/master_production_schedule/fetchByKey.html",
            "/trade/master_production_schedule/header/save.html",
            "/trade/master_production_schedule/header/export.html",
            "/trade/master_production_schedule/header/print.html");

    _InstancePageLines = new MyPageLines();

    $("#tabPanelHeader").wxTabs({tabContent: "tabPanelContent"});

    window.laydate.render({
        elem: '#DateOfContract',
        theme: '#393D49',
        trigger: 'click'
    });

    $("#hPanelSplitter").click(function () {
        if ($(this).children("i").hasClass("fa-angle-double-up")) {
            _InstancePageHeader.Collapse();
        } else {
            _InstancePageHeader.Expand();
        }
    });

    _InstancePageHeader.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
    let wLeftList = 728; //左边列表固定宽度
    let w = $("#panelSlaveData_01").width();

    $("#divH12").css({width: w - wLeftList});
    $("#divD12").css({left: -1, width: w - wLeftList + 1});

    if (_InstancePageLines !== null)
        _InstancePageLines.AutoAdjustTableHeightForLines();
}

//-----------------------------------------------------------------------------
// 验证函数
//-----------------------------------------------------------------------------
$.validator.setDefaults({
    ignore: 'hidden, [reaonly=readonly]'
});
$(function () {
    $("#form_data").validate({
        // Step 1：设置验证规则和错误消息
        rules: {
            _ContractNo: "required",
            _DateOfContract: {
                dateISO: true,
                required: true
            },
            _SaledByName: "required",
            _TradeModeId: "required"
        },
        messages: {
            _ContractNo: "请填写合同号。",
            _DateOfContract: {
                dateISO: "请填写正确的日期。",
                required: "请填写合同日期。"
            },
            _SaledByName: "请填写国际贸易担当。",
            _TradeModeId: "请填写贸易方式。"
        },
        // Step 2：设置验证触发事件
        onclick: false,
        onfocusout: false,
        onfocusin: false,
        onkeyup: false,
        onkeydown: false,
        focusInvalid: false,
        // Step 3：设置错误信息提示
        showErrors: window.showErrors  //使用自定义的错误显示方法
    });
});
// 验证输入
function CheckGridInput() {
    $('#tabData11 tbody').find("tr").each(function (index) {
        let $tr1 = $('#tabData11 tbody').find("tr").eq(index);
        let _quantity = $.trim($tr1.find('td').eq(3).text()).length > 0 ? $.trim($tr1.find('td').eq(3).text()) : 0; // 数量

        if (_quantity !== 0) {
            if (!isNumber(_quantity)) {
                GridCheckErrHandle($tr1, 3, '请输入正确的数字。');
            } else {
                GridCheckSuccessHandle($tr1, 3);
            }
        }
    });
    $('#tabData12 tbody').find("tr").each(function (index) {
        let $tr2 = $('#tabData12 tbody').find("tr").eq(index);
        let _cmt = $.trim($tr2.find('td').eq(11).text()).length > 0 ? $.trim($tr2.find('td').eq(11).text()) : 0; //加工费

        if (_cmt !== 0) {
            if (!isNumber(_cmt)) {
                GridCheckErrHandle($tr2, 11, '请输入正确的数字。');
            } else {
                GridCheckSuccessHandle($tr2, 11);
            }
        }
    });
    if ($('#tabData11 tbody').find('td.error').length > 0 || $('#tabData12 tbody').find('td.error').length > 0) {
        ShowErrorMessagePanel('对不起，填写的数据有错误。');
        return false;
    } else {
        return true;
    }
}
function GridCheckErrHandle($row, index, errMsg) {
    $row.find('td').eq(index).addClass("error");
    $row.find('td').eq(index).attr('title', errMsg);
}
function GridCheckSuccessHandle($row, index) {
    $row.find('td').eq(index).removeClass("error");
    $row.find('td').eq(index).attr('title', '');
}